package day0;
import java.util.Scanner;

import org.junit.Test;

public class Day3Work {
	@Test
	public void test1() {
//		1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//		求出上面数组中0-9分别出现的次数（有一点难度）
		int[] scores = { 0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9 };
		int[] array = new int[10];// 计数器
		int a = 0;
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				array[0]++;
				break;
			case 1:
				array[1]++;
				break;
			case 2:
				array[2]++;
				break;
			case 3:
				array[3]++;
				break;
			case 4:
				array[4]++;
				break;
			case 5:
				array[5]++;
				break;
			case 6:
				array[6]++;
				break;
			case 7:
				array[7]++;
				break;
			case 8:
				array[8]++;
				break;
			case 9:
				array[9]++;
				break;

			default:
				System.out.println("出现错误");
				break;
			}
		}

		for (int i = 0; i < array.length; i++) {
			System.out.println("出现" + i + "共" + array[i] + "次");
		}
	}

	@Test // 方法2
	public void test1_2() {
		int[] scores = { 0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9 };
		// int[] arry = new int[10];

		for (int i = 0; i <= 9; i++) {
			int sum = 0;
			for (int j = 0; j < scores.length; j++) {
				if (scores[j] == i) {
					sum++;
				}

			}
			System.out.println("数字" + i + "有" + sum + "个");
		}
	}

	/*
	 * 2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	 * 要求求出其中的奇数个数和偶数个数。
	 */
	@Test
	public void test2() {
		int[] scores = { 0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9 };
		int odd = 0;// 奇数
		int even = 0;// 偶数
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] % 2 == 0) {
				even++;
			} else {
				odd++;
			}
		}
		System.out.println("数组中奇数个数为" + odd + "个");
		System.out.println("数组中偶数个数为" + even + "个");
	}

	/*
	 * 3、int[] array = [23, 56, 8, 99, 2]; 求数组的最小值和最大值
	 */
	@Test
	public void test3() {
		int[] array = { 23, 56, 8, 23, 99, -23, 2 };
		int max = array[0];// 最大值
		int min = array[0];// 最小值
		for (int i = 0; i < array.length; i++) {
			if (array[i] >= max) {
				max = array[i];				
			}else if (array[i] <= min) {
				min = array[i];
			}
		}
		System.out.println("数组最大值为" + max);
		System.out.println("数组最小值为" + min);
	}

	@Test
	public void test3_1() {
		int[] array = { 23, 56, 8, 23, 99, -23, 2 };
		int max = array[0];// 最大值
		int min = array[0];// 最小值
		for (int i = 0; i < array.length; i++) {
			if (array[i] > max) {
				max = array[i];				
			}else if (array[i] < min) {
				min = array[i];
			}
		}
		System.out.println("数组最大值为" + max);
		System.out.println("数组最小值为" + min);
	}

	/*
	 * 输入月份判断天数（需要用到年份可以输入年份） 1、 3、5、7、8、10、12-------31天 4、6、9、11
	 * --------------------30天 2---------------------------------28/29天
	 */
	@Test
	public void test4() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入月份:");
		int month = scanner.nextInt();

		switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			System.out.println(month + "月份有31天");
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			System.out.println(month + "月份有30天");
			break;
		case 2: {
			System.out.println("请再输入年份");

			int year = scanner.nextInt();
			if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
				System.out.println(year + "的2月份有29天");
			} else {
				System.out.println(year + "的2月份有28天");
			}

			break;
		}
		default:
			System.out.println("信息输入错误");
			break;
		}
	}

	/*
	 * 2、 计算学生成绩的等级(优秀、良好、一般、及格)，使用switch
	 */
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		int score = scanner.nextInt();
		score = score / 10;// 算十位数等级
		switch (score) {
		case 10:
			System.out.println("该生等级为牛逼");
			break;
		case 9:
			System.out.println("该生等级为优秀");
			break;
		case 8:
			System.out.println("该生等级为良好");
			break;
		case 7:
			System.out.println("该生等级为一般");
			break;
		case 6:
			System.out.println("该生等级为及格");
			break;
		default:
			System.out.println("该生等级为不及格");
			break;
		}

	}

}
